Technical Q&A

NW60 - Launching the Default Internet Browser (12-April-99)


Q: My code needs to launch the default Internet browser to open my ".html" help files. I have been told that I need to assign my ".html" files a creator of 'udog', but do I have to write a "browser launcher" or "Connect to.." application to get those files to open?

A: The proper way to invoke the default browser is to use Internet Config. Not only can you use Internet Config to determine the user's default browser, butyou can also cause a URL to be launched.

The following code sample illustrates this:

#include <Types.h>#include <InternetConfig.h>
 OSStatus LaunchURLC(ConstStr255Param urlStr)
{
    OSStatus err;
    ICInstance inst;
    long startSel;
    long endSel;

    err = ICStart(&inst, '????');           // Use your creator code 
if you have one!
    if (err == noErr) {
        err = ICFindConfigFile(inst, 0, nil);
            if (err == noErr) {
                startSel = 0;
                endSel = urlStr[0];
                err = ICLaunchURL(inst, "\p", (char *) &urlStr[1], 
urlStr[0], &startSel, &endSel);
            }
        (void) ICStop(inst);
    }
    return (err);
}
  

Example 1: Using Internet Config to Launch an URL

Documentation on Internet Config itself can be found at the Internet Config web site.

Mac OS 8.5 includes a new user interface, the Internet control panel, for configuring the preferred web browser. However, this control panel stores its preferences using the Internet Config API, as described above, so the code described above works equally well for Mac OS 8.5 and higher. Information about the Internet control panel can be found in the Mac OS 8.5 Technote.

Even if the user is running a system prior to Mac OS 8.5, they are likely to already have Internet Config installed because many third party applications, such as Internet Explorer and Anarchie, install it. The Internet Config web site provides methods to detect the presence of Internet Config.

Browser Launcher is a separate application that's only tangentially related to this problem. Apple installs this application as part of the default OS install. The application's creator code is 'udog'. The purpose of the Browser Launcher application is to redirect the launch of HTML documents to the user's preferred web browser. If you double click an HTML file whose creator is 'udog', the Finder will launch Browser Launcher. Browser Launch then looks up the user's preferred web browser in Internet Config, and then ask thebrowser to open the HTML document.


-- Vinnie Moscaritolo
Worldwide Developer Technical Support

Technical Q&As | Contents
Previous Question | Next Question

To contact us, please use the Contact Us page.